 function ChartCreator() {

 }
ChartCreator.model = 1;
ChartCreator.createPieChart = function() {
    var total =  ChartCreator.model.Contract;
    var dataPoints = [
      {
          x: '材料埋设费', y: parseFloat(ChartCreator.model.MaterialBurySum), text: function ()
          {
              var value = ChartCreator.model.MaterialBurySum;
              var text = (100 * parseFloat(value) / parseFloat(total)).toFixed(0);
              return text.toString() + "%";
          }()
      },
      {
          x: '核定工作量', y: parseFloat(ChartCreator.model.WorkSum), text: function ()
          {
              var value = ChartCreator.model.WorkSum;
              var text = (100 * parseFloat(value) / parseFloat(total)).toFixed(0);
              return text.toString()+"%";
          }()
      },
      {
          x: '其他', y: function ()
          {
              var value = total - ChartCreator.model.MaterialBurySum - ChartCreator.model.WorkSum;
              return parseFloat(value);
          }(), text: function ()
          {
              var value = total - ChartCreator.model.MaterialBurySum - ChartCreator.model.WorkSum;
              var text = (100 * parseFloat(value) / parseFloat(total)).toFixed(0);
              return text.toString() + "%";
          }()
      }];
      $("#chart").ejChart(
      {
          series: [{
              points: dataPoints,
            
              marker: { textOffset: 10 },
              name: 'priceChart', type: 'pie', explode: false,
              pieOptions: { text: { font: { color: '#fff', size: '25px', fontWeight: 'bold' }, fontFamily: 'Courier New' } },
              style: { opacity: 0.8, borderWidth: 1, borderColor: "#888" }
          }
          ],
       
          load:"loadTheme",
          size: { height: 400 },
          text: '  ',
          legend: { visible: true, position: 'top' }
      });
 }
 //材料埋设的图
ChartCreator.createMertirialChart = function() {
  var contentList = ChartCreator.model.ContentGroup;
  var NumberdataPoints = [];
  var PricedataPoints = [];
  for (var i = 0; i < contentList.length; i++) {
    var tempNumberItem = {
      x: contentList[i].ContentName,
      y: contentList[i].Number
    };

    var tempPriceItem = {
      x: contentList[i].ContentName,
      y: contentList[i].Sum
    };
    NumberdataPoints.push(tempNumberItem);
    PricedataPoints.push(tempPriceItem);
  }
 
  $("#chartMertirial").ejChart(
                            {

                                primaryXAxis:
                                  {
                                      title: { text: " " }
                                  },

                                primaryYAxis:
                               {
                                   title: { text: "材料埋设费用" },
                                   labelFormat: '￥{value}'
                               },
                                axes: [
                                       {
                                           majorGridLines:
                                                {
                                                    visible: false,
                                                },
                                           orientation: 'Vertical',
                                           opposedPosition: true,
                                           axisLine: { visible: false },
                                           rangePadding: 'normal',
                                           axisName: 'yAxis',
                                           labelFormat: '{value}个',
                                           title: { text: "材料埋设个数" },
                                       }
                                ],


                                series: [
                                {
                                    points: PricedataPoints,
                                    style:{interior:"#69D2E7"},
                                    name: '材料埋设费用', type: 'column', animation: true,
                                    tooltipFormat: "#point.x# <br/>小计:￥#point.y# <br/>",
                                },
                                {
                                 points: NumberdataPoints,
                                 name: '材料埋设个数', type: 'line', animation: true, yAxisName: 'yAxis',
                                 tooltipFormat: "#point.x# <br/> #point.y#个 <br/>",
                                 marker:
                                {
                                    shape: 'circle',
                                    size:
                                    {
                                        height: 10, width: 10
                                    },
                                    visible: true,
                                },
                                 style: { borderWidth: 2, },

                             },
                                ],
                                load:"loadTheme",
                                showTooltip: true,
                                text: ' ',
                                size: { height: 400 },
                                //textOption: { font: { size: '18px' } }
                                legend: { visible: true, shape: 'rectangle', position: 'Top', itemSize: { width: 15, height: 15 } }
                            });
}


ChartCreator.createWorkChart = function ()
{
    var worklist = ChartCreator.model.Works;
    var NumberdataPoints = [];
    var PricedataPoints = [];
    var PredictPoints = [];
    for (var i = 0; i < worklist.length; i++) {
        var tempNumberItem = {
            x: worklist[i].ContentName,
            y: worklist[i].Number
        };
        var tempPredictItem = {
            x: worklist[i].ContentName,
            y: worklist[i].PredictNo
        }
        var tempPriceItem = {
            x: worklist[i].ContentName,
            y: worklist[i].Sum
        };
        NumberdataPoints.push(tempNumberItem);
        PricedataPoints.push(tempPriceItem);
        PredictPoints.push(tempPredictItem);
    }
    $("#chartWork").ejChart(
                        {
                            rowDefinitions:
                             [{
                                 rowHeight: 50,
                                 lineColor: "#A8A8A8",
                                 lineWidth: 1,
                                 unit: 'percentage'

                             },
                               {
                                   rowHeight: 50,
                                   lineColor: "#A8A8A8",
                                   lineWidth: 1,
                                   unit: 'percentage'
                               }
                             ],
                            primaryXAxis:
                              {
                                  title: { text: "  " }
                              },

                            primaryYAxis:
                           {
                               labelFormat: '￥{value}',
                               axisLine: { visible: false, },
                               title: { text: "费用" },
                           },
                            axes: [
                         {
                             majorGridLines:
                                  {

                                      visible: true,
                                  },
                             orientation: 'Vertical',
                             rowIndex: "1",
                             opposedPosition: false,
                             axisLine: { visible: false },
                             axisName: 'yAxis1',
                             labelFormat: '{value}个',
                             title: { text: "个数" },
                         },

                           {
                               orientation: 'Vertical',
                               hidePartialLabels: true,
                               rowIndex: "1",
                               rangePadding: 'additional',
                               majorGridLines: { visible: false },
                               axisLine: { visible: false },
                               axisName: 'yAxis2',
                               labelFormat: '{value}次',
                               title: { text: "预估次数" },
                               opposedPosition: true,


                           }

                            ],

                            series: [{
                                points: PricedataPoints,
                                name: '费用', type: 'column', style: { interior: "#69D2E7" }, animation: false, tooltipFormat: "#point.x# <br/>  $#point.y#  ",

                            },

                         {
                             points: NumberdataPoints,
                             name: '个数', type: 'line', yAxisName: 'yAxis1', animation: false, tooltipFormat: "#point.x# <br/>  #point.y#个  ",
                             marker:
                            {
                                shape: 'circle',
                                size:
                                {
                                    height: 6, width: 6
                                },
                                visible: true,
                            },
                             style: { borderWidth: 2 },

                         },



               {
                   points: PredictPoints,
                   name: '预估次数', type: 'line', yAxisName: 'yAxis2', animation: false, tooltipFormat: "#point.x# <br/> #point.y#次   ",
                   marker:
                             {
                                 shape: 'circle',
                                 size:
                                 {
                                     height: 6, width: 6
                                 },
                                 visible: true,
                             },
                   style: { borderWidth: 2 },

               }
                            ],

                            load: "loadTheme",
                            showTooltip: true,
                            text: ' ',
                            size: { height: 600 },
                            legend: { visible: true, position: 'top' }
                        });
}

ChartCreator.createChart = function(model) {
  ChartCreator.model = model;
  ChartCreator.createPieChart();
  ChartCreator.createMertirialChart();
  ChartCreator.createWorkChart();
}




